<?php

class Admin_RatesController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
	       $this->_helper->layout->setLayout('admin');	
	       Zend_Loader::loadFile('../application/admin/models/Rates.php');
	        $hotel_id = $this->_getParam('hotel_id', 0);
	       $rates_model = new Rates();
	       $Rate_arr = $rates_model->listRates($hotel_id);
	       // print_r($newsletter_arr); EXIT;
	        $this->view->hotel_id = $hotel_id;
	       $this->view->Rate_arr = $Rate_arr;
     
    }

    public function addAction()
    {
        $this->_helper->layout->setLayout('admin');	
		Zend_Loader::loadFile('../application/admin/forms/Rates.php');
        $Rate_form = new Form_Rates();
        $this->view->title = "Add new Rate";
        $hotel_id = $this->_getParam('hotel_id', 0);
       $this->view->hotel_id = $hotel_id;
        $this->view->Rate_form = $Rate_form;

        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            
            if ($Rate_form->isValid($formData)) {
            	
                $hotel_id=$formData['hotel_id'];
				$rate_category=$formData['rate_category'];
				$rate_basis=$formData['rate_basis'];
				$rate_single=$formData['rate_single'];
				$rate_double=$formData['rate_double'];
				$rate_triple=$formData['rate_triple'];
				$rate_fromdate=$formData['rate_fromdate'];
				$rate_todate=$formData['rate_todate'];
				$rate_additionalinfo=$formData['rate_additionalinfo'];
             
           
           Zend_Loader::loadFile('../application/admin/models/Rates.php');
           $Rate_model = new Rates();
           $Rate_model->addRate($hotel_id,$rate_category,$rate_basis,$rate_single,$rate_double,	$rate_triple,$rate_fromdate,$rate_todate,$rate_additionalinfo);
           $url="/admin/rates/index/hotel_id/".$hotel_id;
           
           $this->_helper->redirector->gotoUrl($url);
            } else {
              
                $Rate_form->populate($formData);
            }
        }
            
    }

    public function editAction()
    {
        $this->_helper->layout->setLayout('admin');	
		Zend_Loader::loadFile('../application/admin/forms/Rates.php');
        $Rate_form = new Form_Rates();
        Zend_Loader::loadFile('../application/admin/models/Rates.php');
        $Rate_model = new Rates();
        $this->view->title = "Add new Rate";
        $hotel_id = $this->_getParam('hotel_id', 0);
        $rate_id = $this->_getParam('rate_id', 0);
        $ratearray=$Rate_model->getrate($rate_id);
        //print_r($ratearray);exit;
        $this->view->hotel_id = $hotel_id;
        $this->view->ratearray = $ratearray;
        $this->view->Rate_form = $Rate_form;

        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            
            if ($Rate_form->isValid($formData)) {
            	
                $hotel_id=$formData['hotel_id'];
				$rate_category=$formData['rate_category'];
				$rate_basis=$formData['rate_basis'];
				$rate_single=$formData['rate_single'];
				$rate_double=$formData['rate_double'];
				$rate_triple=$formData['rate_triple'];
				$rate_fromdate=$formData['rate_fromdate'];
				$rate_todate=$formData['rate_todate'];
				$rate_additionalinfo=$formData['rate_additionalinfo'];
             
           
           
           $Rate_model->editRate($rate_id,$rate_category,$rate_basis,$rate_single,$rate_double,	$rate_triple,$rate_fromdate,$rate_todate,$rate_additionalinfo);
           $url="/admin/rates/index/hotel_id/".$hotel_id;
           
           $this->_helper->redirector->gotoUrl($url);
            } else {
              
                $Rate_form->populate($formData);
            }
        }
        
    }

   /* public function deleteAction()
    {
      $this->_helper->layout->setLayout('admin');	
        if ($this->getRequest()->isPost()) {
            $del = $this->getRequest()->getPost('del');
            if ($del == 'Yes') {
               $Rate_id = $this->getRequest()->getPost('Rate_id');
                Zend_Loader::loadFile('../application/admin/models/Rate.php');
                $Rate_model = new Rate();
                $Rate_model->deleteRate($Rate_id);
            }
            $this->_helper->redirector('index');
        } else {
            $Rate_id = $this->_getParam('Rate_id', 0);
            Zend_Loader::loadFile('../application/admin/models/Rate.php');
            $Rate_model = new Rate();
            $this->view->Rate = $Rate_model->getRate($Rate_id);
       
        }
    }*/
    
         public function deleteAction()
          {
               $this->_helper->layout->setLayout('admin');	
               $Rate_id = $this->_getParam('rate_id', 0);
                $hotel_id = $this->_getParam('hotel_id', 0);
           // echo $Rate_id;exit;
                Zend_Loader::loadFile('../application/admin/models/Rates.php');
                $Rate_model = new Rates();
                $Rate_model->deleteRate($Rate_id);
                 $url="/admin/rates/index/hotel_id/".$hotel_id;
           
                     $this->_helper->redirector->gotoUrl($url);
      
       
           }
    
	
    


}







